﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace HttpSever
{
    class Program
    {
        static void Main(string[] args)
        {
            IPAddress[] ipaddress = Dns.GetHostEntry(Dns.GetHostName()).AddressList;
            string ip = null;
            for (int i = 0; i < ipaddress.Length; i++)
            {
                if (ipaddress[i].AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                {
                    if (ip == null)
                        ip = ipaddress[i].ToString();
                    Console.WriteLine(ipaddress[i].ToString());
                }
            }

            HTTPServer server = new HTTPServer();
            server.onPostEvent += OnPostEvent;
            server.Start(ip, 5555, "test");
            Console.Read();
            server.Close();
        }

        private static void OnPostEvent(List<PostValue> obj)
        {
            for (int i = 0; i < obj.Count; i++)
            {
                if (obj[i].data == null || string.IsNullOrEmpty(obj[i].filename))
                    continue;
                System.IO.File.WriteAllBytes("./" + obj[i].filename, obj[i].data);

            }
        }
    }
}
